﻿using Manon.Admin.Web.Application;
using Manon.Admin.Web.Application.Dtos.News;
using Manon.Core;
using Manon.Repository.Collections;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;

namespace Manon.Admin.Web.Controllers
{
    public class NewsController : Controller
    {
        private readonly INewsService _newsService;
        public NewsController(INewsService newsService)
        {
            _newsService = newsService;
        }

        public IActionResult Index()
        {
            return View();
        }

        public IActionResult Edit()
        {
            return View();
        }


        [Authorize]
        [HttpPost]
        public async Task<PagedList<NewsOutput>> GetNewsPageList([FromBody] GetNewsPagedListInput Input)
        { 
            var result = await _newsService.GetNewsPagedList(Input);

            return result;
        }

        [Authorize]
        [HttpPost]
        public async Task<Result> SaveNews([FromBody] NewsInput Input)
        { 
            var result = await _newsService.SaveNews(Input);
            return result;
        }
        [Authorize]
        [HttpGet]
        public async Task<NewsOutput> GetNews(int id)
        { 
            var result = await _newsService.GetNews(id);
            return result;
        }
        [Authorize]
        [HttpPost]
        public async Task<Result> SetNewsEnabled(int id, bool enabled)
        { 
            var result = await _newsService.SetNewsEnabled(id, enabled);
            return result;
        }
    }
}
